//
//  BCStuffThirdTableCell.m
//  BangcaiBuy
//
//  Created by lsy on 16/6/16.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCStuffThirdTableCell.h"

@interface BCStuffThirdTableCell () <MMNumberKeyboardDelegate>
{
    UIImageView *stuffImgView;
    UILabel *nameLab;
    UILabel *priceLab;
    UILabel *priceLab1;
    UILabel *priceLab2;
    UIButton *style1;
    UILabel *detailLab;
}
@end

@implementation BCStuffThirdTableCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView
{
    
    stuffImgView = [[UIImageView alloc] init];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gopush:)];
    [stuffImgView addGestureRecognizer:tap];
    stuffImgView.userInteractionEnabled = YES;
    nameLab = [[UILabel alloc] init];
    nameLab.font = [UIFont systemFontOfSize:16];
    priceLab = [[UILabel alloc] init];
    priceLab.textColor = [UIColor colorWithRed:0.908  green:0.112  blue:0.114 alpha:1];
    priceLab1 = [[UILabel alloc] init];
    priceLab2 = [[UILabel alloc] init];
    
    detailLab = [[UILabel alloc] init];
    detailLab.textColor = [UIColor lightGrayColor];
    detailLab.numberOfLines = 0;
    detailLab.font = [UIFont systemFontOfSize:14];
    style1 = [UIButton buttonWithType:UIButtonTypeSystem];
    
    [style1 setBackgroundColor:[UIColor randomColor]];

    style1.layer.cornerRadius = 5;
    
     style1.titleLabel.font = [UIFont systemFontOfSize:14];
    style1.tintColor = [UIColor whiteColor];
  
    
    [style1 setTitle:@"高级" forState:UIControlStateNormal];
    
    priceLab.textColor = [UIColor colorWithRed:0.998  green:0.371  blue:0 alpha:1];
    priceLab1.textColor = [UIColor colorWithRed:0.998  green:0.371  blue:0 alpha:1];
    priceLab2.textColor = [UIColor colorWithRed:0.533  green:0.533  blue:0.533 alpha:1];
    priceLab.text = @"¥";
    priceLab.textAlignment = NSTextAlignmentRight;
    priceLab1.text = @"145";
    priceLab2.text = @"/10斤";
    priceLab.font = [UIFont systemFontOfSize:12];
    priceLab1.font = [UIFont systemFontOfSize:18];
    priceLab2.font = [UIFont systemFontOfSize:12];
    
    // Create and configure the keyboard.
    MMNumberKeyboard *keyboard = [[MMNumberKeyboard alloc] initWithFrame:CGRectZero];
    keyboard.returnKeyTitle = @"确认";
    NSDictionary *dic = [keyboard valueForKey:@"buttonDictionary"];
    [dic[@(12)] setValue:BangcaiBlue forKey:@"fillColor"];
    keyboard.allowsDecimalPoint = NO;
    keyboard.delegate = self;
    UIView *accessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40.f)];
    accessoryView.backgroundColor = [UIColor whiteColor];
    UILabel *keyboardTipLable = [[UILabel alloc] initWithFrame:accessoryView.bounds];
    keyboardTipLable.font = [UIFont systemFontOfSize:13];
    keyboardTipLable.textColor = BangcaiBlue;
    keyboardTipLable.text = @"请输入欲购买的数量";
    keyboardTipLable.textAlignment = NSTextAlignmentCenter;
    [accessoryView addSubview:keyboardTipLable];
    
    self.plus = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.plus setImage:[UIImage imageNamed:@"未选择"] forState:UIControlStateNormal];
    [self.plus setImage:[UIImage imageNamed:@"选中"] forState:UIControlStateSelected];
    
    self.plus.userInteractionEnabled = NO;
    
    [self.contentView addSubview:stuffImgView];
    [self.contentView addSubview:nameLab];
    [self.contentView addSubview:priceLab];
    [self.contentView addSubview:priceLab1];
    [self.contentView addSubview:priceLab2];
    [self.contentView addSubview:style1];
     [self.contentView addSubview:detailLab];
    [self.contentView addSubview:self.plus];
    [self.contentView addSubview:style1];
  
    
    
    [self.plus addTarget:self action:@selector(plusAction) forControlEvents:UIControlEventTouchUpInside];
    self.contentView.backgroundColor = [UIColor whiteColor];
    
}


- (void)gopush:(UITapGestureRecognizer*)tap{
    [self.delegate pushWithData:self.data];
}


- (void)plusAction
{
      [self.delegate reloadData];
}

- (void)minusAction{
    [self.delegate reloadData];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
  
    stuffImgView.image = [UIImage imageNamed:@"肉"];
    nameLab.text = _name;

    
    [stuffImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.and.width.mas_equalTo(70 * wx);
        make.top.mas_equalTo(12);
        make.left.mas_equalTo(15 * wx);
    }];
    
    [nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(stuffImgView.mas_top);
        make.left.mas_equalTo(stuffImgView.mas_right).with.offset(12);
        make.height.mas_equalTo(16);
        make.width.mas_equalTo(200 * wx);
    }];
    
    
       [style1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(nameLab.mas_bottom).with.offset(12);
        make.left.equalTo(nameLab);
        make.width.mas_equalTo(60 * wx);
        make.height.mas_equalTo(27);
    }];
    [priceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.plus);
        make.left.equalTo(nameLab).with.offset(-5);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(17);
    }];
    [priceLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(priceLab);
        make.left.mas_equalTo(priceLab.mas_right);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(32);
        
    }];
    
    [priceLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(priceLab);
        make.left.mas_equalTo(priceLab1.mas_right);
        make.height.mas_equalTo(15);
        make.width.mas_equalTo(40);

        
    }];
    
    [self.plus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-12);
        make.bottom.mas_equalTo(-15);
        make.height.and.width.mas_equalTo(27 * wx);
        
    }];
    
    
    
}




@end
